VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "DAOProducto"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit
Private mvarConnection As utilConexion 'local copy

Public Property Set Connection(ByVal vData As utilConexion)
'used when assigning an Object to the property, on the left side of a Set statement.
'Syntax: Set x.Connection = Form1
    Set mvarConnection = vData
End Property


Public Function getBean(ByVal bean As bproducto) As bproducto
On Error GoTo hnderr

Dim result As bproducto
Dim sql As String
Dim rst As New Recordset
sql = "SELECT sCodigo, r.sDescripcion, nEstado, "
sql = sql + " e.sDescripcion as sEstado, nObligatorio, sInvocador FROM recurso r "
sql = sql + " LEFT JOIN estado e ON e.nCodigo=r.nEstado WHERE "
sql = sql + " sCodigo = '" + bean.nCodigo + "' "

rst.Open sql, mvarConnection.Connection, adOpenForwardOnly

If Not rst.EOF Then
    Set result = New bproducto
    If Not IsNull(rst.Fields("ncodigo")) Then result.nCodigo = rst.Fields("ncodigo").value
    If Not IsNull(rst.Fields("sdescripcion")) Then result.sDescripcionCorta = rst.Fields("sdescripcion").value
    If Not IsNull(rst.Fields("nestado")) Then result.bEstado.nCodigo = rst.Fields("nestado").value
    If Not IsNull(rst.Fields("sEstado")) Then result.bEstado.sDescripcion = rst.Fields("sEstado").value
End If
Set getBean = result
hnderr:
If Err.Number = 0 Then Exit Function
Err.Clear
End Function

'---------------------------------------------------------------------------------------
' Procedure : getPagina
' DateTime  : 16/04/2008 23:54
' Author    : Franco
' Purpose   : Obtiene una pagina de productos de la BD
'---------------------------------------------------------------------------------------
'
Public Function getPagina(bean As bproducto, ByRef bpaginador As bpaginador) As Collection
On Error GoTo hnderr
Dim sql As String
Dim rst As New Recordset
Dim list As New Collection
Dim record As New bproducto
Dim bPaginadorRecuperado  As Boolean
sql = "SELECT ncodigo , sdescorta , sdeslarga , ncategoria , scategoria ,"
sql = sql + " nestado , sestado , nprecio , scodbarra,  ntotalregistros from "
sql = sql + " proc_producto_select ( " + CStr(bean.bCategoria.nCodigo) + ","
sql = sql + CStr(bean.bEstado.nCodigo) + "," + CStr(bpaginador.nRegistrosxPagina) + ","
sql = sql + CStr(bpaginador.nIndice) + ")"

rst.Open sql, mvarConnection.Connection, adOpenForwardOnly

While Not rst.EOF
    Set record = New bproducto
    If Not IsNull(rst.Fields("nCodigo")) Then record.nCodigo = rst.Fields("nCodigo").value
    If Not IsNull(rst.Fields("sdescorta")) Then record.sDescripcionCorta = rst.Fields("sdescorta").value
    If Not IsNull(rst.Fields("sdeslarga")) Then record.sDescripcionLarga = rst.Fields("sdeslarga").value
    If Not IsNull(rst.Fields("ncategoria")) Then record.bCategoria.nCodigo = rst.Fields("ncategoria").value
    If Not IsNull(rst.Fields("scategoria")) Then record.bCategoria.sDescripcionCorta = rst.Fields("scategoria").value
    If Not IsNull(rst.Fields("nestado")) Then record.bEstado.nCodigo = rst.Fields("nestado").value
    If Not IsNull(rst.Fields("sestado")) Then record.bEstado.sDescripcion = rst.Fields("sestado").value
    If Not IsNull(rst.Fields("nprecio")) Then record.nPrecio = rst.Fields("nprecio").value
    If Not bPaginadorRecuperado Then
        If Not IsNull(rst.Fields("ntotalregistros")) Then bpaginador.nRegistrosTotal = rst.Fields("ntotalregistros").value
        bpaginador.nPaginas = bpaginador.nRegistrosTotal \ bpaginador.nRegistrosxPagina + IIf(bpaginador.nRegistrosTotal Mod bpaginador.nRegistrosxPagina > 0, 1, 0)
        bPaginadorRecuperado = True
    End If
    rst.MoveNext
    list.Add record
Wend
Set getPagina = list

hnderr:
If Err.Number = 0 Then Exit Function
Err.Clear
End Function

'---------------------------------------------------------------------------------------
' Procedure : getLista
' DateTime  : 16/04/2008 23:54
' Author    : Franco
' Purpose   : Obtiene la lista de productos que coincidan con el parametro
'---------------------------------------------------------------------------------------
'
Public Function getLista(bean As bproducto) As Collection
On Error GoTo hnderr
Dim sql As String
Dim rst As New Recordset
Dim list As New Collection
Dim record As New bproducto

sql = "SELECT ncodigo , sdescorta , sdeslarga , ncategoria , scategoria ,"
sql = sql + " nestado , sestado , nprecio ,scodbarra,  ntotalregistros from "
sql = sql + " proc_producto_select ( " + CStr(bean.bEstado.nCodigo) + ")"

rst.Open sql, mvarConnection.Connection, adOpenForwardOnly

While Not rst.EOF
    Set record = New bproducto
    If Not IsNull(rst.Fields("nCodigo")) Then record.nCodigo = rst.Fields("nCodigo").value
    If Not IsNull(rst.Fields("sdescorta")) Then record.sDescripcionCorta = rst.Fields("sdescorta").value
    If Not IsNull(rst.Fields("sdeslarga")) Then record.sDescripcionLarga = rst.Fields("sdeslarga").value
    If Not IsNull(rst.Fields("ncategoria")) Then record.bCategoria.nCodigo = rst.Fields("ncategoria").value
    If Not IsNull(rst.Fields("scategoria")) Then record.bCategoria.sDescripcionCorta = rst.Fields("scategoria").value
    If Not IsNull(rst.Fields("nestado")) Then record.bEstado.nCodigo = rst.Fields("nestado").value
    If Not IsNull(rst.Fields("sestado")) Then record.bEstado.sDescripcion = rst.Fields("sestado").value
    If Not IsNull(rst.Fields("nprecio")) Then record.nPrecio = rst.Fields("nprecio").value
    If Not IsNull(rst.Fields("scodbarra")) Then record.sCodBarra = rst.Fields("scodbarra").value
    
    rst.MoveNext
    list.Add record
Wend
Set getLista = list

hnderr:
If Err.Number = 0 Then Exit Function
Err.Clear
End Function

